﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EntityFrameworks.Entity.Core.EntityValidation
{
    /// <summary>
    /// 范围验证
    /// </summary>
    [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false)]
    public class RangeAttribute : EntityValidationAttribute
    {
        private System.ComponentModel.DataAnnotations.RangeAttribute innerRangeAttribute;

        public RangeAttribute(double minimum, double maximum, MessageType messageType, params object[] args) :
            base(messageType, args)
        {
            innerRangeAttribute = new System.ComponentModel.DataAnnotations.RangeAttribute(minimum, maximum);
        }

        public RangeAttribute(int minimum, int maximum, MessageType messageType, params object[] args) :
            base(messageType, args)
        {
            innerRangeAttribute = new System.ComponentModel.DataAnnotations.RangeAttribute(minimum, maximum);
        }

        public RangeAttribute(Type type, string minimum, string maximum, MessageType messageType, params object[] args) :
            base(messageType, args)
        {
            innerRangeAttribute = new System.ComponentModel.DataAnnotations.RangeAttribute(type, minimum, maximum);
        }

        public override bool IsValid(object value)
        {
            return innerRangeAttribute.IsValid(value);
        }
    }
}
